package com.djl.mymall.common;

import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.util.List;
@Data
public class CommonPage<T>{
    private Integer pageNum;
    private Integer pageSize;
    private Integer totalPage;
    private long total;
    private List<T> list;

    /**
     * 将pagehelper返回的 pageinfo转为通用的commonPage对象
     * @param list
     * @param <T>
     * @return
     */
    public static <T>CommonPage<T> restPgae(List<T> list){
        CommonPage<T> commonPage=new CommonPage<T>();
        PageInfo<T> pageInfo=new PageInfo<>(list);
        commonPage.setPageNum(pageInfo.getPageNum());
        commonPage.setPageSize(pageInfo.getPageSize());
        commonPage.setTotal(pageInfo.getTotal());
        commonPage.setTotalPage(pageInfo.getPages());
        commonPage.setList(pageInfo.getList());
        return commonPage;
    }


}
